<!DOCTYPE html>
<html>

<head>
    <title>{$node.node_title}</title>
    {include file="common/header"/}
    <el-card class="box-card" shadow="never">
        <div slot="header" class="clearfix">
            <span>修改我的密码</span>
        </div>
        <div class="text item">
            <el-form :model="form" status-icon :rules="rules" ref="form" label-width="80px">
                <el-form-item label="原密码" prop="oldPassword">
                    <el-input show-password v-model="form.oldPassword" placeholder="请输入原密码"></el-input>
                </el-form-item>
                <el-form-item label="新密码" prop="newPassword">
                    <el-input show-password password="password" v-model="form.newPassword" placeholder="请输入新密码">
                    </el-input>
                </el-form-item>
                <el-form-item label="新密码" prop="checkPassword">
                    <el-input show-password v-model="form.checkPassword" placeholder="请确认新密码"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">修改密码</el-button>
                </el-form-item>
            </el-form>
        </div>
    </el-card>
    {include file="common/footer"/}
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    form: {
                        oldPassword: "",
                        newPassword: "",
                        checkPassword: "",
                    },
                    rules: {
                        oldPassword: [
                            { required: true, message: '原密码必须输入', trigger: 'blur' },
                        ],
                        newPassword: [
                            { required: true, pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,16}$/, message: '密码必须包含大小写字母和数字(6-16位)', trigger: 'blur' },
                        ],
                        checkPassword: [
                            { required: true, pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,16}$/, message: '密码必须包含大小写字母和数字(6-16位)', trigger: 'blur' },
                        ],
                    }
                }
            },
            methods: {
                onSubmit() {
                    var that = this;
                    that.$refs['form'].validate((valid) => {
                        if (!valid) {
                            that.$message.error('仔细检查检查，是不是有个地方写得不对？');
                            return;
                        }
                        if (that.form.newPassword != that.form.checkPassword) {
                            that.$message.error('两次密码输入不一致，请确认');
                            return;
                        }
                        axios.post('/api/user/motifypassword', Object.assign({}, PostBase, {
                            oldPassword: that.form.oldPassword,
                            newPassword: that.form.newPassword,
                        }))
                            .then(function (response) {
                                if (response.data.code == CODE_SUCCESS) {
                                    that.$message({
                                        message: response.data.msg,
                                        type: 'success'
                                    });
                                    setTimeout(function () {
                                        location.href = "/admin/user/login";
                                    }, 2000);
                                } else {
                                    that.$message.error(response.data.msg);
                                }
                            })
                            .catch(function (error) {
                                that.$message.error('服务器内部错误');
                                console.log(error);
                            });

                    });
                },
            }
        });
    </script>


</html>